"""
@file Senior.py
@author GalaktiK (jacobliu001@qq.com)
@version 1.0
@date 2020-12-25

@copyright Copyright (c) 2020, Published under License GPLv2
"""
def getHexRepr(x: int) -> str:
    return "%x"%(x)

def transform(x: int) -> str:
    sx = getHexRepr(x)
    acc = 0
    for c in sx:
        acc += int(c, 16)
    sacc = getHexRepr(acc)
    if len(sacc) != 1:
        return transform(acc)
    return sacc

for TC in range(5):
    s, d, r = input().split()
    st = int(s, 16)
    dif = int(d, 16)
    n = int(r)
    acc = 0
    for p in range(n*(n-1)//2, n*(n+1)//2):
        acc += st + p * dif
    print("%d. %s"%(TC+1,transform(acc).upper()))
